<html>
<head><title>Calculator</title></head>
<body>
	<h1>Calculator</h1>
	(Ver 1.0 4/6/2012 by Rhys Yu)<br />
	Type an expression in the following box (e.g., 10.5+20*3/25).
	<form action="<?php $_PHP_SELF ?>" method="POST">
	enter query here: <input type="text" name="name" />
  	<input type="submit" value="calculate" />
  	</form>
</body>
</html>
<?php
$var = $_POST["name"];

//e.g. 2**2, 10//10, 2* do not work
//e.g. **2, //2, --2, ++2
if(preg_match('/^[-*\/\\.+0-9]+$/', $var)){//works for normal ones
	echo "QUERY: " .$var. "<br />";
	//check divide by zero and other math illegals
	if(preg_match('/\/0/', $var)){ //matches divide by 0
		echo "RESULT: invalid input of ".$var;
	}else{
		eval("\$var = $var;");
		echo "RESULT: " .$var;
	}	
}
else{
	echo "QUERY: " .$var. "<br />";
	echo "RESULT: invalid input of ".$var;
}
?>
